package com.tsinghuabigdata.edu.ddmath.module.onlineTutoring.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tsinghuabigdata.edu.ddmath.R;
import com.tsinghuabigdata.edu.ddmath.adapter.CommonAdapter;
import com.tsinghuabigdata.edu.ddmath.adapter.ViewHolder;
import com.tsinghuabigdata.edu.ddmath.module.mycenter.SetHeadImage;
import com.tsinghuabigdata.edu.ddmath.module.onlineTutoring.bean.OnlineTutoring;
import com.tsinghuabigdata.edu.ddmath.view.CircleImageView;

import java.util.List;

import static com.tsinghuabigdata.edu.ddmath.module.neteaseim.NimCache.getContext;

/**
 * 在线辅导——老师列表适配器
 * Created by Administrator on 2017/2/17.
 */

public class OnlineTutoringAdapter extends CommonAdapter<OnlineTutoring> {

    private TutorListener mTutorListener;

    public OnlineTutoringAdapter(Context context, List<OnlineTutoring> mDatas, TutorListener tutorListener) {
        super(context, mDatas);
        mTutorListener = tutorListener;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_online_tutoring;
    }

    @Override
    protected void convert(ViewHolder helper, final int position, final OnlineTutoring item) {

        CircleImageView ivTeacherHead = helper.getView(R.id.iv_teacher_head);
        CheckBox cbAcceptTutor = helper.getView(R.id.cb_accept_tutor);
        LinearLayout llHasQueue = helper.getView(R.id.ll_has_queue);
        TextView tvNoQueue = helper.getView(R.id.tv_no_queue);
        RelativeLayout rlDisacceptTutoring = helper.getView(R.id.rl_disaccept_online_tutoring);
        Button btnSendTutor = helper.getView(R.id.btn_send_tutor);

        if ("1".equals(item.getStates())) {
            cbAcceptTutor.setChecked(true);
            cbAcceptTutor.setText("可接受在线辅导");
            btnSendTutor.setEnabled(true);
            rlDisacceptTutoring.setVisibility(View.INVISIBLE);

            if (item.getStudentCount() > 0) {
                llHasQueue.setVisibility(View.VISIBLE);
                tvNoQueue.setVisibility(View.INVISIBLE);
                helper.setText(R.id.tv_queue_count, "目前队列中还有：" + item.getStudentCount() + "人");
                helper.setText(R.id.tv_wait_time, "预计等待时间："+item.getWaittingTime() + "分");
            } else {
                llHasQueue.setVisibility(View.INVISIBLE);
                tvNoQueue.setVisibility(View.VISIBLE);
            }
        } else {
            cbAcceptTutor.setChecked(false);
            cbAcceptTutor.setText("不可接受在线辅导");
            btnSendTutor.setEnabled(false);
            llHasQueue.setVisibility(View.INVISIBLE);
            tvNoQueue.setVisibility(View.INVISIBLE);
            rlDisacceptTutoring.setVisibility(View.VISIBLE);
        }

        SetHeadImage.setHeadIncomplete(mContext, ivTeacherHead, item.getImageUrl(), R.drawable.ico_teacher_head_normal);
        helper.setText(R.id.tv_teacher_name, item.getTeacherName() + "老师");

        btnSendTutor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTutorListener.sendTutorClick(item, position);
            }
        });
    }

    public interface TutorListener {

        void sendTutorClick(OnlineTutoring onlineTutoring, int position);
    }


}
